package com.coocaa.ops.admin.v1.dmp.tag.provider.impl;

import com.coocaa.ops.admin.v1.dmp.biz.impl.SysUserDisableTagRlsBizImpl;
import com.coocaa.ops.admin.v1.dmp.entity.SysUserDisableTagRlsEntity;
import com.coocaa.ops.admin.v1.dmp.tag.provider.IDmpTagSaveProvider;
import com.coocaa.ops.common.core.base.mybatis.QueryTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author bijiahao
 * @description
 * @date 2020/6/23 15:00
 */
@Service
public class DmpTagSaveProviderImpl implements IDmpTagSaveProvider{
    @Autowired
    private SysUserDisableTagRlsBizImpl sysUserDisableTagRlsBiz;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void saveDisableTag(List<SysUserDisableTagRlsEntity> disableTagRlsEntityList, Integer roleId) {
        QueryTemplate<SysUserDisableTagRlsEntity> wrapper = new QueryTemplate<>();
        wrapper.eq("role_id", roleId);
        if (sysUserDisableTagRlsBiz.getMapper().selectCount(wrapper) > 0) {
            sysUserDisableTagRlsBiz.getMapper().delete(wrapper);
        }
        for (SysUserDisableTagRlsEntity disableTagRlsEntity : disableTagRlsEntityList) {
            sysUserDisableTagRlsBiz.add(disableTagRlsEntity);
        }
    }
}
